import { _decorator, Color, Component, Label, Node, Sprite, Vec2 } from 'cc';
import engine from '../../core/Engine';
const { ccclass, property } = _decorator;

@ccclass('BlockItem')
export class BlockItem extends Component {

    private numLabel: Label = null;
    private spr: Sprite = null;

    protected onLoad(): void {
        this.numLabel = this.node.getChildByPath('Label').getComponent(Label);
        this.spr = this.node.getChildByPath('spr').getComponent(Sprite);
    }

    init(x: number, y: number) {
        this.numLabel.string = ''
        if (x == 6 && y == 6) {
            this.spr.color = Color.RED
            this.numLabel.string = '13'
        }
        if (x == 0 && y == 0) {
            this.spr.color = Color.BLUE
            this.numLabel.string = '1'
        }
    }

    checkPos(initPos: Vec2, isMove: boolean) {
        let pos = this.node.worldPosition //获取物体的世界坐标
        if (isMove) {

            if (pos.x - 50 < initPos.x && pos.x + 50 > initPos.x && pos.y - 50 < initPos.y && pos.y + 50 > initPos.y) {
                this.chnageSprColor(true)
            }
        }
        if (pos.x - 50 < initPos.x && pos.x + 50 > initPos.x && pos.y - 50 < initPos.y && pos.y + 50 > initPos.y) {
            return true
        }
        return false
    }

    getPos() {
        return this.node.worldPosition
    }

    start() {

    }

    chnageSprColor(colorType: boolean) {
        if (colorType) {
            this.spr.color = Color.BLUE
        } else {
            this.spr.color = Color.WHITE
        }
    }

}


